package org.common.utils.fasttest;

import java.util.function.Consumer;

/**
 * @author zhouzhibing
 * @date 2024/3/22
 */
public class Test {

    /**
     *
     * @param desc 测试描述
     * @param testCount 测试数量
     * @param roundCount  测试次数
     * @param run 执行内容
     */
    public static void doHandler(String desc , long testCount , long roundCount, Consumer<Integer> run) {
        for (int i = 0; i < testCount; i++) {
            run.accept(i);
        }

        long totalUseTime = 0;
        for (int i = 0; i < roundCount; i++) {
            long startTime = System.currentTimeMillis();
            for (int j = 0; j < testCount; j++) {
                run.accept(i);
            }
            long useTime = System.currentTimeMillis() - startTime;
            System.out.println(desc + ", useTime : " + useTime + ", testCount : " + testCount);
            totalUseTime += useTime;
        }
        System.out.println(roundCount + "次，总使用时间：" + totalUseTime + "， 平均使用时间：" + (totalUseTime / roundCount));
    }
}
